-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the option to set ttl from a column. #274
base: master
Are you sure you want to change the base?
Conversation
SariNusier
commented
Nov 26, 2020
•
edited
Loading
edited
- If ttl.column is set, the connector will use the value in that column to set the ttl of the record.
- The ttl column will not be included in the fields of the record.
- If ttl.column is set, the connector will use the value in that column to set the ttl of the record. - The ttl column will not be included in the fields of the record. - The ability to use a constant ttl is still there, but ttl.column takes precedence when both are set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @SariNusier
Thank you for the PR! It looks good in general.
Could you please also update documentation and tests?
@@ -25,7 +25,7 @@ class BinaryRedisPersistence extends RedisPersistence[Array[Byte]] { | |||
override def load(pipeline: Pipeline, key: String, requiredColumns: Seq[String]): Unit = | |||
pipeline.get(key.getBytes(UTF_8)) | |||
|
|||
override def encodeRow(keyName: String, value: Row): Array[Byte] = { | |||
override def encodeRow(keyName: String, value: Row, ttlColumn: Option[String] = None): Array[Byte] = { | |||
val fields = value.schema.fields.map(_.name) | |||
val valuesArray = fields.map(f => value.getAs[Any](f)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we exclude TTL column here as well?
@@ -39,6 +39,13 @@ class HashRedisPersistence extends RedisPersistence[Any] { | |||
// don't store key values | |||
k != keyName | |||
} | |||
.filter { case (k, _) => | |||
// don't store TTLs | |||
ttlColumn match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably more efficient in terms of the performance to check if ttlColumn is specified only once rather than for every field.
val encodedRow = persistence.encodeRow(keyName, row) | ||
persistence.save(pipeline, key, encodedRow, ttl) | ||
val encodedRow = persistence.encodeRow(keyName, row, ttlColumn) | ||
val recordTTL = if (ttlColumn.isEmpty) ttl else row.getAs[Int](ttlColumn.get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rewrite it with val recordTTL = ttlColumn.map(v => row.getAs[Int](v)).getOrElse(ttl)
. It looks to be more idiomatic approach.